/**
 * 加载中
 * @author heke
 * @version 20170512
 */
import _ from 'lodash'

const state = {
    isLoadingActive: false,
    loadingText: '加载中'
}

const getters = {
    isLoadingActive: state => state.isLoadingActive,
    loadingText: state => state.loadingText
}

const actions = {
    showLoading ({ commit }, text) {
        commit('SHOW_LOADING', { text })
    },
    hideLoading ({ commit }) {
        commit('HIDE_LOADING')
    }
}

const mutations = {
    'SHOW_LOADING' (state, { text }) {
        state.isLoadingActive = true
        state.loadingText = _.isNil(text) ? '加载中' : text
    },
    'HIDE_LOADING' (state) {
        state.isLoadingActive = false
    }
}

export default {
    state,
    getters,
    actions,
    mutations
}
